#include "GameEngine.h"

#include <stdio.h>
int won (unsigned char ** board, unsigned char c) {
  if (board == NULL)
    return -1;

  if (board[0][0] == c && board[1][0] == c && board[2][0] == c)
    return 1;

  if (board[0][1] == c && board[1][1] == c && board[2][1] == c)
    return 1;

  if (board[0][2] == c && board[1][2] == c && board[2][2] == c)
    return 1;

  if (board[0][0] == c && board[0][1] == c && board[0][2] == c)
    return 1;

  if (board[1][0] == c && board[1][1] == c && board[1][2] == c)
    return 1;

  if (board[2][0] == c && board[2][1] == c && board[2][2] == c)
    return 1;

  if (board[0][0] == c && board[1][1] == c && board[2][2] == c)
    return 1;

  if (board[0][2] == c && board[1][1] == c && board[2][0] == c)
    return 1;

  return 0;
}

void paint (unsigned char ** board) {
  if (board == NULL)
     return;

  int i, j;

  for (i = 0; i < 3; i++) {
    for (j = 0; j < 3; j++)
      printf("%c", board[i][j]);
    printf("\n");
  }
}

int perform_step (unsigned char ** board, unsigned char * step) {
  if (board == NULL || step == NULL)
    return -1;

  board[step[1]][step[0]] = step[2];

  return 0;
}
